/*
 *  YATUN  - Yet another tunneling application
 *
 *  Michal Demin - 2007
 *
 *  SchedQueue.h
 *
 */

#ifndef SCHEDQUEUE_H_
#define SCHEDQUEUE_H_

#include <sys/time.h>

#include "Yatun.h"
#include "c_Plug_IO.h"

struct SchedQueueConf {
    unsigned long MaxQueued;
    int DynamicTimeout;
    int DynamicMult;
    
    struct timeval RetryTimeout;
    struct timeval MAXTimeout;
    struct timeval MINTimeout;

};

struct _eQueue {
    struct _eQueue *Next;
    
    struct timeval Timestamp;
    Packet *Pack;
};

class SchedQueue {
	
	private:
		unsigned short SeqNum; 
		unsigned long Queued;
		unsigned long MaxQueued;
		unsigned long Resent;
		int DynamicTimeout;
		int DynamicMult;
		int Full;
		
		_eQueue* Queue;
		_eQueue* QueueLast;	
		c_Plug_IO *IO;
		
		struct timeval RetryTimeout;
		struct timeval MAXTimeout;
		struct timeval MINTimeout;
		struct timeval RTATime;
		
		void ComputeRTA(struct timeval &a);
		
    public:
		SchedQueue();
		~SchedQueue();
	
		void SetIO(c_Plug_IO *);
		void SetMaxQueued(int);
		void SetResendTimeout(struct timeval &a);
		void SetResendMAXTimeout(struct timeval &a);
		void SetResendMINTimeout(struct timeval &a);
		void SetDynamicTimeout(int);
		void SetDynamicMul(int);
		
		void SetConf(struct SchedQueueConf &a);
		
		int AddSend(Packet *);
		int Check();
		int Remove(int);
		int IsFull();
		void FlushQueue();
};

#endif /*SCHEDQUEUE_H_*/
